<template>
  <div class="login-container">
    <!-- 右侧切换主题、语言按钮  -->
    <!-- <div class="action-bar">
      <el-tooltip :content="t('login.themeToggle')" placement="bottom">
        <CommonWrapper>
          <DarkModeSwitch />
        </CommonWrapper>
      </el-tooltip>
      <el-tooltip :content="t('login.languageToggle')" placement="bottom">
        <CommonWrapper>
          <LangSelect size="text-20px" />
        </CommonWrapper>
      </el-tooltip>
    </div> -->
    <!-- 登录页主体 -->
    <div class="login-main">
      <div class="login-card">
        <div class="login-content">
          <!-- logo -->
          <div class="login-logo">
            <img src="@/assets/logo.png" alt="Logo" />
          </div>

          <!-- 标题 -->
          <div class="login-header">
            <h1 class="login-title">
              <el-badge :value="`v ${defaultSettings.version}`" type="success">
                {{ defaultSettings.title }}
              </el-badge>
            </h1>
            <p class="login-subtitle">{{ t("login.welcomeMessage") || "欢迎使用企业管理系统" }}</p>
          </div>

          <!-- 组件切换 -->
          <transition name="fade-slide" mode="out-in">
            <component :is="formComponents[component]" v-model="component" class="login-form" />
          </transition>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import defaultSettings from "@/settings";
import CommonWrapper from "@/components/CommonWrapper/index.vue";
import DarkModeSwitch from "@/components/DarkModeSwitch/index.vue";

type LayoutMap = "login" | "register" | "resetPwd";

const t = useI18n().t;

const component = ref<LayoutMap>("login"); // 切换显示的组件
const formComponents = {
  login: defineAsyncComponent(() => import("./components/Login.vue")),
  register: defineAsyncComponent(() => import("./components/Register.vue")),
  resetPwd: defineAsyncComponent(() => import("./components/ResetPwd.vue")),
};
</script>

<style lang="scss" scoped>
.login-container {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100vh;
  background: var(--login-bg-color);
  overflow: hidden;
}

// 添加背景装饰
.login-container::before {
  position: fixed;
  top: 0;
  left: 0;
  z-index: -1;
  width: 100%;
  height: 100%;
  content: "";
  background:
    radial-gradient(circle at 20% 80%, rgba(0, 124, 198, 0.1) 0%, transparent 50%),
    radial-gradient(circle at 80% 20%, rgba(0, 124, 198, 0.08) 0%, transparent 50%),
    linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
}

.login-main {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 420px;
  padding: 40px;
  background: var(--login-card-bg);
  box-shadow: var(--login-card-shadow);
  border: 1px solid var(--login-border-color);
  border-radius: 16px;
  backdrop-filter: blur(10px);
  transition: all 0.3s ease;

  &:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 40px rgba(0, 124, 198, 0.15);
  }
}

.login-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

.login-logo {
  margin-bottom: 24px;

  img {
    width: 80px;
    height: 80px;
    object-fit: contain;
  }
}

.login-header {
  text-align: center;
  margin-bottom: 32px;

  .login-title {
    font-size: 28px;
    font-weight: 700;
    color: var(--login-text-primary);
    margin-bottom: 8px;
    line-height: 1.2;
  }

  .login-subtitle {
    font-size: 16px;
    color: var(--login-text-secondary);
    margin: 0;
    line-height: 1.5;
  }
}

.login-form {
  width: 100%;
}

.action-bar {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 10;
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 8px;
  backdrop-filter: blur(10px);
  border: 1px solid var(--login-border-color);
  font-size: 1.125rem;

  @media (max-width: 480px) {
    top: 10px;
    right: auto;
    left: 10px;
  }

  @media (min-width: 640px) {
    top: 40px;
    right: 40px;
  }
}

/* fade-slide */
.fade-slide-leave-active,
.fade-slide-enter-active {
  transition: all 0.3s ease;
}

.fade-slide-enter-from {
  opacity: 0;
  transform: translateX(-30px);
}

.fade-slide-leave-to {
  opacity: 0;
  transform: translateX(30px);
}
</style>
